/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.monitor.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.modules.monitor.dto.ChartDTO;
import org.springblade.modules.monitor.pojo.StorageCenterVO;
import org.springblade.modules.monitor.pojo.SwitchVO;
import org.springblade.modules.monitor.pojo.ThreeLayerSwitchVO;
import org.springblade.modules.monitor.service.IHostInfoService;
import org.springblade.modules.monitor.service.INetEquipInfoService;
import org.springblade.modules.monitor.vo.EquipKindGroup;
import org.springblade.modules.monitor.vo.ItemChartResult;
import org.springblade.modules.monitor.vo.NetEquipInfoVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

/**
 *  控制器
 *
 * @author Blade
 * @since 2020-05-17
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-monitor/netequipinfo")
@Api(value = "网络设备信息", tags = "网络设备信息接口")
public class NetEquipInfoController extends BladeController {

	private INetEquipInfoService netEquipInfoService;

	private IHostInfoService hostInfoService;

	/**
	 * 详情 厂商等新信息
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "interfaceid")
	@ApiIgnore
	public R<NetEquipInfoVO> detail(Long interfaceid) {
		NetEquipInfoVO detail = netEquipInfoService.getDetail(interfaceid);
		return R.data(detail);
	}


	/**
	 * 存储设备详情
	 */
	@GetMapping("/storagecenter")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "存储设备详情", notes = "interfaceid")
	public R<StorageCenterVO> getStorageCenterDetail(Long interfaceid) {
		StorageCenterVO storageCenterVO = netEquipInfoService.getStorageCenterDetail(interfaceid);
		return R.data(storageCenterVO);
	}


	/**
	 * 三层交换机详情
	 */
	@GetMapping("/threelayerswitch")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "三层交换机详情", notes = "interfaceid")
	public R<ThreeLayerSwitchVO> getThreeLayerSwitchDetail(Long interfaceid) {
		ThreeLayerSwitchVO threeLayerSwitchDetail = netEquipInfoService.getThreeLayerSwitchDetail(interfaceid);
		return R.data(threeLayerSwitchDetail);
	}


	/**
	 * 三层交换机详情
	 */
	@GetMapping("/switch")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "交换机详情", notes = "interfaceid")
	public R<SwitchVO> getSwitchDetail(Long interfaceid) {
		SwitchVO switchVO = netEquipInfoService.getSwitchDetail(interfaceid);
		return R.data(switchVO);
	}


	/**
	 * 获取端口数据交换信息
	 */
	@GetMapping("/portbytesinfo")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取端口数据交换信息", notes = "获取端口发送、接收等字节速度")
	public R<List<ItemChartResult>> getPortBytesInfo(ChartDTO chartDTO) {
		List<ItemChartResult> chartDTOList = netEquipInfoService.getPortBytesInfo(chartDTO);
		return R.data(chartDTOList);
	}

	/**
	 * 获取CPU、内存使用情况
	 */
	@GetMapping("/equipCpuOrMemoryInfo")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "网络设备CPU、内存使用趋势（折线图）等", notes = "获取服务器CPU、内存使用情况（交换机、三层交换机使用；存储设备无）")
	public R<List<ItemChartResult>> getEquipCpuOrMemoryInfo(ChartDTO chartDTO) {
		List<ItemChartResult> chartDTOList = hostInfoService.getCpuOrMemoryInfo(chartDTO);
		return R.data(chartDTOList);
	}


	@GetMapping("/equipkind")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "网络设备列表", notes = "描述设备所属种类及设备名称")
	public R<List<EquipKindGroup>> getEquipKind() {

		List<EquipKindGroup> list = netEquipInfoService.getEquipKind();
		List<EquipKindGroup> result = new ArrayList<>();
		list.forEach(x->{
			if(!"25".equals(x.getEquipKind())){
				result.add(x);
			}
		});
		return R.data(result);
	}

	@GetMapping("/storages")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "存储设备列表", notes = "存储设备列表")
	public R<List<EquipKindGroup>> getStorages() {
		List<EquipKindGroup> list = netEquipInfoService.getEquipKind();
		List<EquipKindGroup> result = new ArrayList<>();
		list.forEach(x->{
			if("25".equals(x.getEquipKind())){
				result.add(x);
			}
		});
		return R.data(result);
	}
}
